<template>
	<view class="content">
		<view v-if="type==2770">
			<view class="article-tab">
				<view @click="tabActive=2770" :class="tabActive===2770?'active':''" class="tab-item">就业补贴政策</view>
				<view @click="tabActive=2771" :class="tabActive===2771?'active':''" class="tab-item">见习补贴政策</view>
			</view>
		</view>
		<view v-if="type==2103||type==2104||type==2135">
			<view class="article-tab">
				<view @click="tabActive=2103" :class="tabActive==2103?'active':''" class="tab-item">通知公告</view>
				<view @click="tabActive=2104" :class="tabActive==2104?'active':''" class="tab-item">工作动态</view>
				<view @click="tabActive=2135" :class="tabActive==2135?'active':''" class="tab-item">招聘信息</view>
			</view>
		</view>
		<view v-if="type==2143">
			<view class="article-tab">
				<view @click="tabActive=2143" :class="tabActive==2143?'active':''" class="tab-item">政策类</view>
				<view @click="tabActive=2144" :class="tabActive==2144?'active':''" class="tab-item">法规类</view>
			</view>
		</view>
		<view v-if="type==2145">
			<view class="article-tab">
				<view @click="tabActive=2145" :class="tabActive==2145?'active':''" class="tab-item">政策类</view>
				<view @click="tabActive=2148" :class="tabActive==2148?'active':''" class="tab-item">法规类</view>
			</view>
		</view>
		<view v-if="type==2146">
			<view class="article-tab">
				<view @click="tabActive=2146" :class="tabActive==2146?'active':''" class="tab-item">政策类</view>
				<view @click="tabActive=2149" :class="tabActive==2149?'active':''" class="tab-item">法规类</view>
			</view>
		</view>
		<view v-if="type==2147">
			<view class="article-tab">
				<view @click="tabActive=2147" :class="tabActive==2147?'active':''" class="tab-item">政策类</view>
				<view @click="tabActive=2150" :class="tabActive==2150?'active':''" class="tab-item">法规类</view>
			</view>
		</view>
		<block v-if="newsList.length>0">
			<view class="block list-block" v-if="tabActive!=1">
				<view @click="navigate('/page_other/article/detail?id='+item.id)" class="list-item policy-item"
					v-for="(item,index) in newsList" :key="item.id">
					<image mode="aspectFill" :src="item.ima_url" class="cover-photo"></image>
					<view class="info">
						<view class="title overflow-line">{{item.title}}</view>
						<view class="abstract">{{item.abstract}}</view>
						<view class="time">发布时间：{{item.crt_time}}</view>
					</view>
				</view>
			</view>
		</block>
		
		<view v-else class="empty">暂无数据</view>
	</view>
</template>

<script>
	import {
		getNewsList as getNewsListApi
	} from '@/api/notice.js'
	export default {
		data() {
			return {
				tabActive: 0,
				newsList: [],
				type: null,
				page: 1,
				limit: 10,
				lay: 3,
			}
		},
		watch: {
			tabActive: {
				handler(val) {
					if (val != 0) {
						this.getNewsList()
					} 
				},
				immediate: true
			},
		},
		methods: {
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			getNewsList() {
				getNewsListApi({
					page: this.page,
					limit: this.limit,
					type: this.tabActive
				}).then((res) => {
					console.log(res)
					this.newsList = res.list ?? [];
				})
			},
		},
		onLoad(e) {
			this.type = e.type;
			this.tabActive = e.type;
			this.lay = e.lay
			
			
		}
	}
</script>

<style lang="scss">
	page {
		background: #FAFAFA;
	}

	.content {
		width: 100%;
		padding: 0 30rpx;

		.article-tab {
			width: 100%;
			height: 70rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			font-weight: bold;
			font-size: 34rpx;
			color: #313131;

			.tab-item {
				margin-right: 30rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.tab-item.active {
				color: #FF0014;
				//border-bottom: 2px solid #DE6349;
				height: 100%;
			}

			.tab-item:last-child {
				margin: 0;
			}
		}

		.block.tab-block {
			box-shadow: none;
			display: flex;
			flex-direction: row;
			justify-content: left;
			flex-wrap: wrap;

			.tab-item {
				padding: 10rpx 15rpx;
				font-weight: bold;
				font-size: 30rpx;
				margin-right: 30rpx;
			}

			.tab-item.active {
				background: url("https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/job_hunting/home/tab_selected_bg.png") no-repeat right bottom;
				background-size: 45%;
				font-size: 32rpx;
			}
		}

		.list-block.block {
			margin-top: 30rpx;
			width: 100%;
			display: flex;
			flex-direction: column;

			.list-item {
				width: 100%;
				background: #fff;
				border-radius: 10rpx;
				box-shadow: 0 0 10px 0 #efefef;
				padding: 20rpx;
				display: flex;
				flex-direction: row;
				justify-content: center;

				.list-info {
					width: 100%;
					display: flex;
					flex-direction: column;

					>view {
						width: 100%;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}

					.title {
						color: #000;
						font-weight: bold;
						font-size: 34rpx;
					}

					.address {
						color: #999;
						font-size: 26rpx;
						margin-top: 20rpx;
					}

					.label-block {
						font-size: 24rpx;
						display: flex;
						flex-direction: row;
						flex-wrap: wrap;
						justify-content: left;
						margin-top: 20rpx;

						.label-item {
							padding: 8rpx 20rpx;
							background: #F5F6F8;
							color: #999;
							margin: 0 10rpx 20rpx 0;
						}
					}

					.wage {
						color: #FE7526;
						font-size: 36rpx;
						font-weight: bold;

						.unit {
							font-size: 28rpx;
							font-weight: normal;
						}
					}
				}
			}

			.list-item.policy-item {
				height: 220rpx;
				width: 100%;
				padding: 30rpx 0;
				display: flex;
				flex-direction: row;
				border-radius: 20rpx;
				background: #fff;
				margin-bottom: 30rpx;
				padding: 20rpx;
				box-shadow: 0 0 10px 0 #efefef;

				.cover-photo {
					width: 180rpx;
					height: 180rpx;
					border-radius: 10rpx;
					margin-right: 20rpx;
					background: #efefef;
				}

				.info {
					width: calc(100% - 200rpx);
					height: 100%;

					.title {
						font-weight: bold;
					}

					.abstract {
						font-size: 24rpx;
						color: #999;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
						margin-top: 10rpx;
						line-height: 1.5;
					}

					.time {
						margin-top: 10rpx;
						font-size: 28rpx;
						color: #999;
					}
				}
			}

		}
	}
</style>
